package src.com.zt.demo.digtal;

import java.util.Scanner;

public class GuessDigital {
    public static void main(String[] args) {
        int num = (int) (Math.random() * 100); //math.random()返回的是0到1之间的double数字
        int guess;  //定义一个要猜的变量
        System.out.println("数字=" + num);
        Scanner sc = new Scanner(System.in);    //从控制台获取要猜的数
        System.out.println("请输入要猜的数字：");
        guess = sc.nextInt();   //获取控制台的nextInt
        while (guess != num) {
            if (guess > num) {
                System.out.println("你猜的数字" + guess + "太大了");
            } else {
                System.out.println("你猜的数字" + guess + "太小了");
            }
            System.out.println("要猜的数字是：" + num);
            System.out.println("请重新输入要猜的数字：");
            guess = sc.nextInt();   //获取控制台的nextIn
        }

        System.out.println("数字猜对了，你猜的数字是：" + num);
    }
}
